package tool;

import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultStatsUtil;
import org.apache.hadoop.hbase.util.Bytes;
import org.yecht.Data;

public class CellTool {
    public static String GetRowName(Cell cell)
    {
        return Bytes.toString(CellUtil.cloneRow(cell));
    }
    public static String GetRowName(Result result)
    {
        return Bytes.toString(result.getRow());
    }
    public static String GetColName(Cell cell)
    {
        return Bytes.toString(CellUtil.cloneQualifier(cell));
    }
    public static String GetValue(Cell cell)
    {
        return Bytes.toString(CellUtil.cloneValue(cell));
    }
    public static String GetValue(Result result,String family,String qulify)
    {
        Cell cell = result.getColumnLatestCell(Bytes.toBytes(family), Bytes.toBytes(qulify));
        return GetValue(cell);
    }
    public static String GetColFamily(Cell cell)
    {
        return Bytes.toString(CellUtil.cloneFamily(cell));
    }
    public static String Cell2Str(Cell cell)
    {
        StringBuffer sb = new StringBuffer();
        sb.append("RowName=").append(GetRowName(cell)).append(";");
        sb.append("ColFamily=").append(GetColFamily(cell)).append(";");
        sb.append("ColName=").append(GetColName(cell)).append(";");
        sb.append("Value=").append(GetValue(cell)).append(";");
        return sb.toString();
    }
    public static String Result2Row(Result result)
    {
        Cell[] cells = result.rawCells();
        StringBuffer sb = new StringBuffer();
        for (Cell cell:cells)
        {
            sb.append(GetValue(cell)).append("|");
        }
        return sb.toString();
    }

}
